package com.yf.controller.web;

import com.google.common.collect.Lists;
import com.yf.enums.pagemodel.GPSHistoryPage;
import com.yf.enums.pagemodel.VehicleEventPage;
import com.yf.enums.pagemodel.VehiclePage;
import com.yf.form.GPSHistoryForm;
import com.yf.form.VehicleEventForm;
import com.yf.form.VehicleForm;
import com.yf.model.GPSHistory;
import com.yf.model.Vehicle;
import com.yf.model.VehicleEvent;
import com.yf.model.VehicleRealStatus;
import com.yf.pagination.PageParams;
import org.apache.log4j.Logger;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 车辆服务
 *
 * @author wangbiao
 * @date 2016-08-18 10：51
 */
@RestController
@RequestMapping
public class VehicleController implements IVehicleController {

    private static final Logger LOGGER = Logger.getLogger(VehicleController.class);

    @Override
    @RequestMapping(value = "/vehicles" ,method = RequestMethod.GET)
    public ResponseEntity<VehiclePage> list(@RequestParam(required = false) VehicleForm vehicleForm, @RequestParam(required = true) PageParams pageParams){

        VehiclePage page=new VehiclePage();
        List<Vehicle> list= Lists.newArrayList();
        Vehicle v=new Vehicle();
        v.setId(1);
        list.add(v);
        page.setRows(list);
        ResponseEntity<VehiclePage> entity=new ResponseEntity<VehiclePage>(page, HttpStatus.OK);
        return entity;
    }

    @Override
    @RequestMapping(value = "/vehicles/id/plates" ,method = RequestMethod.GET)
    public ResponseEntity<VehiclePage> plates(@RequestParam(required = false) Integer userId){

        VehiclePage page=new VehiclePage();
        List<Vehicle> list= Lists.newArrayList();
        Vehicle v=new Vehicle();
        v.setId(1);
        list.add(v);
        page.setRows(list);
        ResponseEntity<VehiclePage> entity=new ResponseEntity<VehiclePage>(page,HttpStatus.OK);
        return entity;
    }

    @Override
    @RequestMapping(value = "/vehicles/{id}" ,method = RequestMethod.GET)
    public ResponseEntity<Vehicle> id(@PathVariable(value = "id") Integer id) {
        Vehicle v=new Vehicle();
        v.setId(1);
        ResponseEntity<Vehicle> entity=new ResponseEntity<Vehicle>(v,HttpStatus.OK);
        return entity;
    }

    @Override
    @RequestMapping(value = "/vehicles" ,method = RequestMethod.POST)
    public ResponseEntity<Void> saveVehicle(@RequestParam Vehicle vehicle) {
        LOGGER.info("新增成功！");
        return null;
    }

    @Override
    @RequestMapping(value = "/vehicles/id" ,method = RequestMethod.PUT)
    public ResponseEntity<Void> modifyVehicle(@RequestParam Vehicle vehicle) {
        LOGGER.info("修改成功！");
        return null;
    }

    @Override
    @RequestMapping(value = "/vehicles/{id}" ,method = RequestMethod.DELETE)
    public ResponseEntity<Void> removeVehicleById(@PathVariable(value = "id") Integer id) {
        LOGGER.info("删除成功！");
        return null;
    }

    @Override
    @RequestMapping(value = "/vehicles/{id}/check" ,method = RequestMethod.PUT)
    public ResponseEntity<Boolean> checkVehicleInfo(@PathVariable Integer id, @RequestParam String auditStatus) {

        return new ResponseEntity(Boolean.TRUE,HttpStatus.OK);
    }

    @Override
    @RequestMapping(value = "/vehicle/realtime/status/{id}" ,method = RequestMethod.GET)
    public ResponseEntity<VehicleRealStatus> queryVehicleRealStatus(@PathVariable(value = "id")Integer id) {
        VehicleRealStatus vrs = new VehicleRealStatus();
        vrs.setId(1);
        vrs.setCarPlate("川A54SS46");
        ResponseEntity<VehicleRealStatus> entity=new ResponseEntity<VehicleRealStatus>(vrs,HttpStatus.OK);
        return entity;
    }

    @Override
    @RequestMapping(value = "/vehicle/events" ,method = RequestMethod.GET)
    public ResponseEntity<VehicleEventPage> eventList(@RequestParam(required = false) VehicleEventForm vehicleEventForm, @RequestParam PageParams pageParams){
        VehicleEventPage page=new VehicleEventPage();
        List<VehicleEvent> list= Lists.newArrayList();
        VehicleEvent v=new VehicleEvent();
        v.setId(1);
        list.add(v);
        page.setRows(list);
        ResponseEntity<VehicleEventPage> entity=new ResponseEntity<VehicleEventPage>(page,HttpStatus.OK);
        return entity;

    }

    @Override
    @RequestMapping(value = "/gps/histories" ,method = RequestMethod.GET)
    public ResponseEntity<GPSHistoryPage> gps(@RequestParam GPSHistoryForm gpsHistoryForm, @RequestParam PageParams pageParams){

        GPSHistoryPage page=new GPSHistoryPage();
        List<GPSHistory> list= Lists.newArrayList();
        GPSHistory v=new GPSHistory();
        v.setId(1);
        list.add(v);
        page.setRows(list);
        ResponseEntity<GPSHistoryPage> entity=new ResponseEntity<GPSHistoryPage>(page,HttpStatus.OK);
        return entity;
    }

    @Override
    @RequestMapping(value = "/vehicle/events/{id}" ,method = RequestMethod.GET)
    public ResponseEntity<VehicleEvent> queryVehicleEventById(@PathVariable Integer id) {

        VehicleEvent v=new VehicleEvent();
        v.setId(1);
        ResponseEntity<VehicleEvent> entity=new ResponseEntity<VehicleEvent>(v,HttpStatus.OK);
        return entity;
    }
}

